package com.example.juc.test;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Ticket2 {

    private int num = 40;

    Lock lock = new ReentrantLock();
    public void sale(){
        lock.lock();
        try {
            if(num>0){
                System.out.println(Thread.currentThread().getName()+"卖出了"+num--+"票，剩余"+num);
            }
        }catch (Exception e){

        }finally {
            lock.unlock();
        }
    }
}

